package com.swf.common.jar;

import java.util.*;

import org.dom4j.*;
import org.slf4j.*;

import com.swf.common.exception.*;
import com.swf.common.utils.*;

/**
 * description:遍历xml的元素
 * @version 1.0 2013-5-16
 * @author shenwf
 */
public class ClassInfoVisitor extends VisitorSupport{
	private Map<String,ClassInfo> classInfoMap =new HashMap<String, ClassInfo>();
	private static Logger logger = LoggerFactory
			.getLogger(ClassInfoVisitor.class);
	
	public ClassInfoVisitor() {
	}
	
	@Override
	public void visit(Element element) {
		
		String labelName = element.getName();
		if ("classInfo".equals(labelName)){
			ClassInfo classInfo = new ClassInfo();
			String id = element.attributeValue("id");
			if (FwsStringUtils.isBlank(id)){
				Exception e= new FwsException("id不能为空");
				logger.error(e.getMessage(), e);
			}
			String from = element.attributeValue("from");
			String to = element.attributeValue("to");
			classInfo.setId(id);
			classInfo.setFrom(from);
			classInfo.setTo(to);
			Iterator<Element> iterator = element.elementIterator("jar");
			while (iterator.hasNext()){
				Element jarEmt = iterator.next();
				Jar jar = new Jar();
				jar.setName(jarEmt.attributeValue("name"));
				jar.setAdd(!"false".equalsIgnoreCase(jarEmt.attributeValue("add")));
				jar.setPath(jarEmt.attributeValue("path"));
				classInfo.addJar(jar);
			}
			classInfoMap.put(id, classInfo);
		}
	}

	public Map<String, ClassInfo> getResourceMap() {
		return classInfoMap;
	}
	
}
